<template>
  <!-- 销项 -->
  <a-modal
    title="销项"
    class="normal-modal page-detail"
    :visible="visible"
    @cancel="$emit('update:visible', false)"
  >
    <template slot="footer">
      <!-- <a-button :loading="loading" key="submit" type="primary" @click="submit">提交</a-button> -->
      <a-button
        key="save"
        :loading="loading"
        type="primary"
        @click="save"
      >
        提交
      </a-button>
      <a-button
        key="back"
        @click="$emit('update:visible', false)"
      >
        取消
      </a-button>
    </template>
    <a-form-model
      ref="formRules"
      :model="form"
      :rules="formRules"
    >
      <a-row>
        <a-col span="24">
          <a-form-model-item
            label="销项说明"
            prop="salesContent"
          >
            <b-textarea v-model="form.salesContent" />
          </a-form-model-item>
        </a-col>
        <a-col span="24">
          <a-form-model-item label="上传附件">
            <b-upload
              business-code="LCM10"
              upload-type="single"
              :file-list.sync="form.fileInfoVO"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </a-modal>
</template>

<script>
import riskListApi from '@/api/legal/risk/list'

export default {
  name:'a'+Date.now(),
  props: {
    id: {
      type: String,
      default: ''
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loading: false,
      form: {},
      formRules: {
        salesContent: { required: true, message: '销项说明不能为空', trigger: 'blur' }
      }
    }
  },
  methods: {
    save() {
      this.$refs.formRules.validate(async (valid) => {
        if (valid) {
          this.$confirm({
            title: '提交过后不可修改，确定提交',
            onOk: () => {
              let submitForm = this.$clone(this.form)
              submitForm.baseId = this.id
              submitForm.fileInfoVO = Array.isArray(submitForm.fileInfoVO)
                ? submitForm.fileInfoVO?.[0]
                : submitForm.fileInfoVO
              return riskListApi.editBySales(submitForm).then((res) => {
                if (res.code === this.SUCCESS_CODE) {
                  this.$noticeSuccess('提交成功')
                  this.$emit('update:visible', false)
                  this.$emit('ok')
                }
              })
            }
          })
        } else {
          this.$noticeWarning('请填写完整')
        }
        resolve(false)
      })
    }
  }
}
</script>

<style scoped>
</style>
